package com.example.crmdemo.Crm.controller;

import com.example.crmdemo.Crm.entity.Area;
import com.example.crmdemo.Crm.entity.Goods;
import com.example.crmdemo.Crm.entity.Person;
import com.example.crmdemo.Crm.service.AreaService;
import com.example.crmdemo.Crm.service.GoodsService;
import com.example.crmdemo.Crm.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private PersonService personService;

    @Autowired
    private AreaService areaService;

    // 添加物资
    @PostMapping("/add")
    public boolean addGoods(@RequestBody Goods goods) {
        return goodsService.save(goods);
    }

    // 删除物资
    @DeleteMapping("/delete/{name}")
    public boolean deleteGoods(@PathVariable String name) {
        return goodsService.removeById(name);
    }

    // 修改物资信息
    @PutMapping("/update")
    public boolean updateGoods(@RequestBody Goods goods) {
        return goodsService.updateById(goods);
    }

    // 按物资名查询物资
    @GetMapping("/get/{name}")
    public Goods getGoodsByName(@PathVariable String name) {
        return goodsService.getById(name);
    }

    // 获取所有物资信息
    @GetMapping("/getall")
    public List<Goods> getAllGoods() {
        return goodsService.list();
    }

    // 获取所有人员信息
    @GetMapping("/persons")
    public List<Person> getAllPersons() {
        return personService.list();
    }

    // 获取所有区域信息
    @GetMapping("/areas")
    public List<Area> getAllAreas() {
        return areaService.list();
    }
}
